/*
	This file is part of "Ants on the web".

    "Ants on the web" is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    "Ants on the web" is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with "Ants on the web".  If not, see <http://www.gnu.org/licenses/>.
*/

package org.utc.ia04.antsontheweb.gui.surveillance;

import java.awt.BorderLayout;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JTextArea;

public class InterfaceSurveillance extends JFrame implements PropertyChangeListener
{
	private static final long serialVersionUID = 1L;
	private AgentInterfaceSurveillance myAgent;
	
	//Attributes
	int ressourceNeeded;
	
	//Frame resources
	JProgressBar collectedResource;
	JTextArea warning;
	
	public InterfaceSurveillance(AgentInterfaceSurveillance a, int _ressourceNeeded)
	{
		super("Ants On The Web -- Big Brother Client");
		
		myAgent = a;
		ressourceNeeded = _ressourceNeeded;
		
		initialFrame();
		myAgent.addPropertyChangeListener(this);
	}
	
	public AgentInterfaceSurveillance getMyAgent()
	{
		return myAgent;
	}
	
	public void initialFrame()
	{
		//Initialisation
		JPanel mainPane = new JPanel();
		setContentPane(mainPane);
		BorderLayout mainPainLayout = new BorderLayout();
		mainPane.setLayout(mainPainLayout);
		
		setVisible(true);
		setSize(500, 200);

		//Avancement
		JPanel avancementPanel = new JPanel();
		BorderLayout avancementPanelLayout = new BorderLayout();
		avancementPanel.setLayout(avancementPanelLayout);
		mainPane.add(avancementPanel, BorderLayout.NORTH);
		avancementPanel.setBorder(BorderFactory.createTitledBorder("AC State"));
		
		collectedResource = new JProgressBar(0, ressourceNeeded);
		collectedResource.setValue(0);
		avancementPanel.add(collectedResource, BorderLayout.CENTER);
		avancementPanel.add(new JLabel("Avancement : "), BorderLayout.WEST);
		
		//Warning
		JPanel errorPanel = new JPanel();
		BorderLayout errorPanelLayout = new BorderLayout();
		errorPanel.setLayout(errorPanelLayout);
		mainPane.add(errorPanel, BorderLayout.CENTER);
		errorPanel.setBorder(BorderFactory.createTitledBorder("Error message"));
		
		warning = new JTextArea();
		errorPanel.add(warning, BorderLayout.CENTER);
	}

	public void propertyChange(PropertyChangeEvent arg0)
	{
		if(arg0.getPropertyName().equals(AgentInterfaceSurveillance.UPDATE_DATA))
			collectedResource.setValue((Integer)arg0.getNewValue());
		else if(arg0.getPropertyName().equals(AgentInterfaceSurveillance.NOTIFY_ERROR))
			warning.setText(warning.getText() + (String)arg0.getNewValue() + "\n");
	}
}
